home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Goodies / 3rd Party Demos / 3rd Party Plugins / Misc / MongoToDCon Plugin / Alfred's MongoToDebugConsole next >
Encoding:
Text File  |  2000-03-22  |  11.4 KB  |  194 lines

  1.  
  2. MongoToDebugConsole, the tool you will need to debug your REALbasic Project.  It is a cross-platform REALbasic Plugin that funnels information from your project back to the C/C++ environment, where it is further processed.
  3.  
  4.  
  5.  
  6. Version 1.1.0 alpha, 3/22/2000
  7.  
  8. The first release contains the following Note:  in WIN32 any nil will generate a unhandled exception and leads to a freeze.  This is a bug in the initial version.  This bug has been solved, so nil pointers will yield a nil (0) address and a locknumber (0).
  9.  
  10. Apparently the MacOS and MacsBug with "EBBE ON" did not catch such unhandled exceptions.  Such an exception was the attempt to dereference a nil Handle.  It has been corrected.    
  11.  
  12.  
  13.  
  14. Version 1.0.0 alpha, 3/19/2000
  15.  
  16. ® Alfred N. Van Hoek, Ph.D./Massachusetts General Hospital
  17.    vanhoek@receptor.mgh.harvard.edu
  18.             Without SoftWindows98 on a MacOS9 host I would not be able to test the WIN32 compatibility of the plugin.  
  19.  
  20.  
  21. What is so cool about remote debugging consoles?
  22. Plugin writers for REALbasic, and other programmers who do most of the programming in C/C++ will use debugging tools to determine critical points in their developement of a program, plugin or code, and many approaches and resources are out there.  One of the best ways to debug that also allow you to determine where the freeze occurs is by remote debugging.  Not everybody has such resources available and other means are investigated that should meet a certain purpose.  We've got MacsBug, we've also got a debugging feature built in REALbasic IDE, but we also have experiences that when a project runs perfectly in the IDE, that that not necessarily means it will compile, or will not crash after a built.  If MacsBug is installed, the crash will throw us into something we do not understand, or you could have built in your project debug strings that will bring you into MacsBug.  What you actually want is that the program keeps running, while recording certain debugging messages.  Nathan at Virtual1 has written CuisinArt that puts a lot of those debugging stuff into your project and messages will appear in a console.  However, this console is part of your modified project. When your project crashes, the console crashes too.  His approach though is similar to debugging strings send to a remote console in the C/C++ environment.  And because "remote" consoles for debugging are for free, why not give REALbasic the ability to use a remote console.
  23.  
  24. About The REALbasic-Plugin MongoToDebugConsole
  25. MongoToDebugConsole is a 68K, PPC and WIN32 compatible REALbasic plugin that provides REALbasic with a "MongoToDCon" Class.  The purpose of this plugin is to give you access to information about all the REALbasic objects in your project.  This information is send to a debugging console, which is not part of your project.  The name Mongo has been used, because CuisinArt from Virtual1 lead me to write this plugin.  The drawback of that program is that the console "Mongotrace" is part of the program you want to debug.  Using independent consoles to which messages are send exceptions can be catched that remain after your project crashes.
  26.  
  27. MacOS: DCon -DEMO, System Based Extension Console
  28. For the MacOS, the DCon-debugging console used to be available at http://www.cache-computing.com/ (see the separate information documents), but apparently cache-computing is out-of-business.  Emails that I have send do not arrive, and using the provided phone-number yields a disconnecting message.  The only way to obtain this Console is thus by distrubution through third parties. One possibility is to check your CodeWarrior Version 5 CD, if you have one, because you can find DCon-Demo on the CW-5 disk.  The other possibility is to request people to send you the DEMO, ask through the lists for instance, some people of the RB-community should have CW5, or had it earlier downloaded from cach-computing. I believe that when someone sending this, it is better than when you would download it.  Just a legal thing.  
  29.  
  30. Win32: DebugView/EE, An Application Console
  31. For the WIN32 platform you can download the DebugView/EE for Windows NT/9x Version 3.24, dbgv98 folder, by Mark Russinovich.  It has lots of possibilities to dump, intervene etc., and to do remote debugging through the internet, that's cool!  The address is: http://www.sysinternals.com
  32.  
  33.  
  34. SoftWindows98:  A Fairly Convenient Way to Debug your WIN32 Project
  35. Apparently, SoftWindows98, v 5.0.9, runs pretty robust on a G3-MacOS9 machine.  I have a 400 MHz, 128 MB G3 powerbook that gives a good performance for debugging purposes.
  36.  
  37. MongoToDebugConsole: the way it works.
  38. Plugin:  simple plugin which will register a class, called MongoToDconClass, that has properties,  methods, and an event. To make it damn clear: if you do not like CuisinArt, no big deal! You do not need it; write your own debugging code in your project, it will work too.
  39.  
  40. Event
  41. The event, CallBack, you could use for your own purpose. It does not send messages to the console though. To implement the event, you must subclass MongoToDconClass. So, in REALbasic you create a class and set its super to MongoToDconClass. In the events list you will see the Callback event. To use it, you must put some code inside it.
  42.  
  43. Sub Callback()
  44.     Msgbox "Mongo was here"
  45. End Sub
  46.  
  47. To execute the code, you need to create an instance of your MongoToDconClass subclass, and call its Run method. This will end up with the Callback event being called and the REALbasic code you supplied for that event will be executed.
  48.  
  49. Sub Action()
  50.     Dim myDcon as myMongoToDconClass 
  51.     myDcon = new MongoToDconClass
  52.    myDcon.run
  53. End Sub
  54.  
  55. Stick the above in a pushbutton, and you ought to get a messagebox thrown up.
  56.  
  57.  
  58. Properties
  59.  
  60. Properties of the MongoToDcon class are:
  61.  
  62. MongoToDcon.Str as String 
  63. MongoToDcon.Picture as Picture
  64. MongoToDcon.Graphics as Graphics
  65. MongoToDcon.Control as Control
  66. MongoToDcon.Object as Object 
  67. MongoToDcon.Window as Window 
  68. MongoToDcon.FolderItem as FolderItem
  69. MongoToDcon.DatabaseCursor as DatabaseCursor
  70. MongoToDcon.Database as Database
  71. MongoToDcon.Socket as Socket 
  72.  
  73. #if  targetMacOS
  74.                 MongoToDcon.Movie as Movie 
  75.                 MongoToDcon.Sound as Sound
  76.                 MongoToDcon.AppleEvent as AppleEvent
  77. #endif
  78.  
  79. Once a property is assigned a message is generated to the console:
  80.  
  81. Do this:
  82.  
  83. dim mDcon as MongoToDcon
  84. dim pic as picture
  85. dim g as graphics
  86. dim s as sound
  87. dim m as movie
  88. dim w as window
  89. dim c as control
  90. dim o as object
  91. dim f as folderitem
  92. dim dBase as database
  93. dim dcurs as databasecursor
  94. dim ae as appleEvent
  95. dim
  96.  
  97. //Instantiate a sub class by
  98.  
  99. mDcon= new MongoToDcon
  100.  
  101. // assign properties that generates text in console, here some examples
  102.  
  103. mDcon.str = myString                                                //    or 
  104.                         mDcon.str = "Hello World" // "Hello World" will appear
  105. mDcon.picture = pic // " picture address (2ae455f) lockPicture (3)
  106. mDcon.graphics = g        // " graphics address(2ae46df) lockGraphics (4)
  107. mDcon.window = w
  108. mDcon.movie = nil   // " movie address (0) lockMovie (0)
  109. mDcon.object = o
  110. mDcon.control = c
  111. mDcon.sound = s
  112. mDcon.folderitem = f
  113. mDcon.database = dbase
  114. mDcon.databaseCursor = dcurs
  115.  
  116. Note:  in WIN32 any nil will generate a unhandled exception and leads to a freeze. 
  117.  
  118. Some of these properties are obviously redundant, but useful if you want to discriminate between a Window, control, class or another object other then seeing object address...., object address..., object address...  The same holds for the methods below.
  119.  
  120.  
  121. Methods
  122. (if you do not have or do not want to use remote consoles, but want to see addressing and locking numbers)
  123. Methods:
  124.  
  125. MongoString(s as String) as string
  126. MongoPicture(pic as Picture) as string
  127. MongoGraphics(g as Graphics) as string
  128. MongoControl(con as Control) as string
  129. MongoFolderItem(f as FolderItem) as string
  130. MongoSocket(s as Socket) as string
  131. MongoDatabaseCursor(cur as DatabaseCursor) as string
  132. MongoDatabase(db as Database) as string
  133. MongoWindow(win as Window) as string
  134. MongoObject(obj as Object) as string
  135. #ifndef WIN32
  136. MongoMovie(mov as Movie) as string
  137. MongoSound(s as Sound) as string
  138. MongoAppleEvent(a as AppleEvent) as string
  139. #endif
  140.  
  141. These methods do the same thing as when using the property, i.e. sending debugging strings to the console, but they return also these strings to the RB-environment. If you do not want to use consoles, these strings can be used within the project.  This means these strings will appear in the MongoTrace Console of Virtual1_CuisinArt project.
  142.  
  143.  
  144.  
  145.  
  146. Here is an example to send strings to Dcon or dbgView, using Virtual1's MongoWIN where you need to define a property (global to the MongoWIN Window) like : mdcon as MongoToDcon
  147.  
  148. In the open event of MongoWIN do this:
  149.  
  150. Sub Open()
  151. mdcon = new MongoToDcon
  152. end Sub
  153.  
  154. In the already defined method do this to modify it:
  155.  
  156. Sub MongoTrace(Indenting as boolean, This as string)
  157.                     dim myString as string
  158.                     dim MongoDisk as FolderItem
  159.                     dim MongoText as TextOutputStream
  160.                     Me.hide                                                                                                                                    //hide the cuisineArt_console 
  161.  
  162.                 if Indenting then
  163.                                     Indent=Indent+"  "
  164.                 end if
  165.                 //EditField1.SelText=Indent+This+chr(13)      not necessary
  166.                 //EditField1.SelStart=lenb(EditField1.Text)            not necessary
  167.  
  168.                 mdcon.str = indent + this
  169.  
  170.                 if not Indenting then
  171.                             Indent=midb(Indent,3)
  172.                 end if
  173. end Sub
  174.  
  175.  
  176.  
  177. Having this MongoToDCon class with properties, it allows for the following assignment myString = MongoToDcon.Str, or myPicture = MongoToDcon.Picture.
  178.  
  179. For what its worth you may need this feature to pass-on objects.  Let me know if it would be useful, and if other features are required.
  180.  
  181. The internals of REALbasic:  Addressing and lockNumbers,  what it means and how you could use it to your advantage.
  182. The address you will get for an object or instance of an object is given in a hexadecimal number.  If it is nul it means no address.  If it is very large, usually an 8 digit number, it also means a nil pointer, or a pointer waggling in the breeze.  The lock-count-number also indicates that the pointer points to something or nothing.  If it is nul it means that the pointer points to garbage, and RB will collect it as garbage.  Sometimes you will notice a lock-count-number in the 7-hexadecimal digit range.  This also means that the pointer points to garbage.  If everything would be perfect, any valid pointer will point to an instance that would have a lock-number of 1 or 2.  If you see 5 or 6, it would mean that 5, respectively, 6 pointers are pointing to the instance.  This is the way REALbasic works; as long as the lock-number is 1 or higher it will not be garbage collected.  An example of a locknumber of 5 is encountered for a listbox in a window.  Why it should be 5 is related to internal structures within REALbasic.  It is 5 under MacOS, but 6 under WIN32.  Strings usually have a lock-number of 2 to 3, graphics 3, pictures 2, etc,  Check them out.  If for some reason the lock number of an instance is increasing, it probably is a sign of a memory leak.
  183.  
  184. Since James Milne came to RB, he had put into REALbasic a lot of debugging strings that appeared in the debugging console DCon.  In time many of these strings have been removed, but if you start up REALbasic with Dcon enabled you will see "AppearancePak installed".  It does not come from your debugging code.  Also, if you have a placard in the window, additional messages can be observed.  On the WIN32 platform you will notice other messages, such as NuList::Nulist for a listbox. Don't worry, it is because we are using alpha releases.                                                             
  185.  
  186.  
  187. And now HAPPY DEBUGGING,
  188.  
  189. Alfred,
  190.  
  191. 3/19/2000.
  192.  
  193. enjoy
  194.